/**
 * 
 */
package org.tinygroup.remoteconfig.placeholder;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.apache.commons.lang.StringUtils;
import org.tinygroup.remoteconfig.IRemoteConfigConstant;

/**
 * 占位符规则
 * 
 * @author yanwj06282
 *
 */
public class HostNameHander implements PlaceHolderHander{

	public String handle(String str){
		return StringUtils.replace(str, IRemoteConfigConstant.HOST_NAME, getHostName());
	}
	
	private String getHostName(){
        InetAddress addr;
		try {
			addr = InetAddress.getLocalHost();
			return addr.getHostName();
		} catch (UnknownHostException e) {
			throw new RuntimeException("获取主机hostname失败！", e);
		}
	}
	
}
